package com.xgpro.mapper.rolemanage;

import com.xgpro.domain.rolemanage.entity.Permissions;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface PermissionsMapper extends Mapper<Permissions> {


    @Select("<script>" +
            "select t1.id as id,t1.permissions_name as permissionsName,t1.type as type,t1.description as description,t1.code as code " +
            "from t_permissions t1,t_role_permissions t2 WHERE t1.id = t2.permissions_id and t2.role_id = #{roleId}" +
            "</script>")
    List<Permissions> findListByRoleId(Integer roleId);

    @Select("<script>" +
            "SELECT count(1) from t_role_permissions WHERE permissions_id = #{permissionsId}" +
            "</script>")
    int queryCountByPermId(Integer permissionsId);

    @Select("<script>" +
            " select permissions_id from t_role_permissions where role_id = #{roleId} AND permissions_id in ( " +
            " select id from t_permissions where pid = #{pid}) " +
            "</script>")
    List<Integer> findPerIdByRoleId(@Param("roleId") Integer roleId, @Param("pid") Integer pid);
}
